package demo04_bean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * Created by ztt on 2017/9/16.
 */
@Component
public class UserService {

    @Bean
    public OrgService orgService(){
        return new OrgService(orgDao());
    }

    @Bean
    public OrgService orgService2(){
        return new OrgService(orgDao());
    }

    /** 其实任意方法都可以 **/
    @Bean
    public OrgDao orgDao(){
        return new OrgDao();
    }
}

@Component
class OrgService{

    private OrgDao dao;

    @Autowired
    public OrgService(OrgDao dao){
        this.dao=dao;
    }

    public OrgDao get(){
        System.out.println("dao："+dao);
        dao.get();
        return dao;
    }
}

@Component
class OrgDao{

    public void get(){
        System.out.println("获取机构信息……");
    }
}
